package org.sxf.app.sign.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lidroid.xutils.util.LogUtils;

import org.sxf.app.sign.R;
import org.sxf.app.sign.data.DataCacheSingleton;

/**
 * Created by zqc on 17/1/19.
 */

public class SignHistoryListAdapter extends BaseAdapter {


    private LayoutInflater mInflater;


    public SignHistoryListAdapter(LayoutInflater inflater){
        mInflater = inflater;
    }


    @Override
    public int getCount() {
        try {
            return DataCacheSingleton.getInstance().getSignHistory().size();
        }catch (Exception e){
            return 0;
        }
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        LogUtils.d("getView:," + i);
        ViewHolder holder;
        //观察convertView随ListView滚动情况
        if (view == null) {
            view = mInflater.inflate(R.layout.sign_list_view_cell,null);
            holder = new ViewHolder();
            try {
                /**得到各个控件的对象*/
                holder.bgLayout = (RelativeLayout)view.findViewById(R.id.signBgLayout);
                holder.signTimeTextView = (TextView) view.findViewById(R.id.signTimeTextView);
                holder.corpNameTextView = (TextView) view.findViewById(R.id.signCorpNameTextView);
                view.setTag(holder);//绑定ViewHolder对象



            }catch (Exception e){

            }


        }
        else{
            holder = (ViewHolder)view.getTag();//取出ViewHolder对象
        }


        try {
            holder.signTimeTextView.setText(DataCacheSingleton.getInstance().getSignHistory().get(i).signTime);
            holder.corpNameTextView.setText(DataCacheSingleton.getInstance().getSignHistory().get(i).corpName);
        }catch (Exception e){

        }

        if (i == 0){
            holder.bgLayout.setBackgroundResource(R.mipmap.list_view_bg_blue);
            holder.signTimeTextView.setTextColor(mInflater.getContext().getResources().getColor(R.color.sign_list_text));
            holder.corpNameTextView.setTextColor(mInflater.getContext().getResources().getColor(R.color.sign_list_text));
        }else {
            holder.bgLayout.setBackgroundResource(R.mipmap.list_view_bg_gray);
            holder.signTimeTextView.setTextColor(mInflater.getContext().getResources().getColor(R.color.sign_list_text_gray));
            holder.corpNameTextView.setTextColor(mInflater.getContext().getResources().getColor(R.color.sign_list_text_gray));
        }



        return view;

    }


    public final class ViewHolder {
        public TextView corpNameTextView;
        public TextView signTimeTextView;
        public RelativeLayout bgLayout;
    }

}
